<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>alpha_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_color_alpha_test.js.html">alpha_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>goog.provide(&#39;goog.color.alphaTest&#39;);
<a name="line15"></a>goog.setTestOnly(&#39;goog.color.alphaTest&#39;);
<a name="line16"></a>
<a name="line17"></a>goog.require(&#39;goog.array&#39;);
<a name="line18"></a>goog.require(&#39;goog.color&#39;);
<a name="line19"></a>goog.require(&#39;goog.color.alpha&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>
<a name="line22"></a>function testIsValidAlphaHexColor() {
<a name="line23"></a>  var goodAlphaHexColors = [&#39;#ffffffff&#39;, &#39;#ff781259&#39;, &#39;#01234567&#39;, &#39;#Ff003DaB&#39;,
<a name="line24"></a>                            &#39;#3CAF&#39;, &#39;#abcdefab&#39;, &#39;#3CAB&#39;];
<a name="line25"></a>  var badAlphaHexColors = [&#39;#xxxxxxxx&#39;, &#39;88990077&#39;, &#39;not_color&#39;, &#39;#123456789&#39;,
<a name="line26"></a>                           &#39;fffffgfg&#39;];
<a name="line27"></a>  for (var i = 0; i &lt; goodAlphaHexColors.length; i++) {
<a name="line28"></a>    assertTrue(goodAlphaHexColors[i],
<a name="line29"></a>        goog.color.alpha.isValidAlphaHexColor_(goodAlphaHexColors[i]));
<a name="line30"></a>  }
<a name="line31"></a>  for (var i = 0; i &lt; badAlphaHexColors.length; i++) {
<a name="line32"></a>    assertFalse(badAlphaHexColors[i],
<a name="line33"></a>        goog.color.alpha.isValidAlphaHexColor_(badAlphaHexColors[i]));
<a name="line34"></a>  }
<a name="line35"></a>}
<a name="line36"></a>
<a name="line37"></a>function testIsValidRgbaColor() {
<a name="line38"></a>  var goodRgbaColors = [&#39;rgba(255, 0, 0, 1)&#39;, &#39;rgba(255,127,0,1)&#39;,
<a name="line39"></a>                        &#39;rgba(0,0,255,0.5)&#39;, &#39;(255, 26, 75, 0.2)&#39;,
<a name="line40"></a>                        &#39;RGBA(0, 55, 0, 0.6)&#39;, &#39;rgba(0, 200, 0, 0.123456789)&#39;];
<a name="line41"></a>  var badRgbaColors = [&#39;(255, 0, 0)&#39;, &#39;(2555,0,0, 0)&#39;, &#39;(1,2,3,4,5)&#39;,
<a name="line42"></a>                       &#39;rgba(1,20,)&#39;, &#39;RGBA(20,20,20,)&#39;, &#39;RGBA&#39;,
<a name="line43"></a>                       &#39;rgba(255, 0, 0, 1.1)&#39;];
<a name="line44"></a>  for (var i = 0; i &lt; goodRgbaColors.length; i++) {
<a name="line45"></a>    assertEquals(goodRgbaColors[i], 4,
<a name="line46"></a>                 goog.color.alpha.isValidRgbaColor_(goodRgbaColors[i]).length);
<a name="line47"></a>  }
<a name="line48"></a>  for (var i = 0; i &lt; badRgbaColors.length; i++) {
<a name="line49"></a>    assertEquals(badRgbaColors[i], 0,
<a name="line50"></a>                 goog.color.alpha.isValidRgbaColor_(badRgbaColors[i]).length);
<a name="line51"></a>  }
<a name="line52"></a>}
<a name="line53"></a>
<a name="line54"></a>function testIsValidHslaColor() {
<a name="line55"></a>  var goodHslaColors = [&#39;hsla(120, 0%, 0%, 1)&#39;, &#39;hsla(360,20%,0%,1)&#39;,
<a name="line56"></a>                        &#39;hsla(0,0%,50%,0.5)&#39;, &#39;HSLA(0, 55%, 0%, 0.6)&#39;,
<a name="line57"></a>                        &#39;hsla(0, 85%, 0%, 0.123456789)&#39;];
<a name="line58"></a>  var badHslaColors = [&#39;(255, 0, 0, 0)&#39;, &#39;hsla(2555,0,0, 0)&#39;, &#39;hsla(1,2,3,4,5)&#39;,
<a name="line59"></a>                       &#39;hsla(1,20,)&#39;, &#39;HSLA(20,20,20,)&#39;,
<a name="line60"></a>                       &#39;hsla(255, 0, 0, 1.1)&#39;, &#39;HSLA&#39;];
<a name="line61"></a>  for (var i = 0; i &lt; goodHslaColors.length; i++) {
<a name="line62"></a>    assertEquals(goodHslaColors[i], 4,
<a name="line63"></a>                 goog.color.alpha.isValidHslaColor_(goodHslaColors[i]).length);
<a name="line64"></a>  }
<a name="line65"></a>  for (var i = 0; i &lt; badHslaColors.length; i++) {
<a name="line66"></a>    assertEquals(badHslaColors[i], 0,
<a name="line67"></a>                 goog.color.alpha.isValidHslaColor_(badHslaColors[i]).length);
<a name="line68"></a>  }
<a name="line69"></a>}
<a name="line70"></a>
<a name="line71"></a>function testParse() {
<a name="line72"></a>  var colors = [&#39;rgba(15, 250, 77, 0.5)&#39;, &#39;(127, 127, 127, 0.8)&#39;, &#39;#ffeeddaa&#39;,
<a name="line73"></a>                &#39;12345678&#39;, &#39;hsla(160, 50%, 90%, 0.2)&#39;];
<a name="line74"></a>  var parsed = goog.array.map(colors, goog.color.alpha.parse);
<a name="line75"></a>  assertEquals(&#39;rgba&#39;, parsed[0].type);
<a name="line76"></a>  assertEquals(goog.color.alpha.rgbaToHex(15, 250, 77, 0.5), parsed[0].hex);
<a name="line77"></a>  assertEquals(&#39;rgba&#39;, parsed[1].type);
<a name="line78"></a>  assertEquals(goog.color.alpha.rgbaToHex(127, 127, 127, 0.8), parsed[1].hex);
<a name="line79"></a>  assertEquals(&#39;hex&#39;, parsed[2].type);
<a name="line80"></a>  assertEquals(&#39;#ffeeddaa&#39;, parsed[2].hex);
<a name="line81"></a>  assertEquals(&#39;hex&#39;, parsed[3].type);
<a name="line82"></a>  assertEquals(&#39;#12345678&#39;, parsed[3].hex);
<a name="line83"></a>  assertEquals(&#39;hsla&#39;, parsed[4].type);
<a name="line84"></a>  assertEquals(&#39;#d9f2ea33&#39;, parsed[4].hex);
<a name="line85"></a>
<a name="line86"></a>  var badColors = [&#39;rgb(01, 1, 23)&#39;, &#39;(256, 256, 256)&#39;, &#39;#ffeeddaa&#39;];
<a name="line87"></a>  for (var i = 0; i &lt; badColors.length; i++) {
<a name="line88"></a>    var e = assertThrows(badColors[i] + &#39; is not a valid color string&#39;,
<a name="line89"></a>        goog.partial(goog.color.parse, badColors[i]));
<a name="line90"></a>    assertContains(&#39;Error processing &#39; + badColors[i],
<a name="line91"></a>        &#39;is not a valid color string&#39;, e.message);
<a name="line92"></a>  }
<a name="line93"></a>}
<a name="line94"></a>
<a name="line95"></a>function testHexToRgba() {
<a name="line96"></a>  var testColors = [[&#39;#B0FF2D66&#39;, [176, 255, 45, 0.4]],
<a name="line97"></a>                    [&#39;#b26e5fcc&#39;, [178, 110, 95, 0.8]],
<a name="line98"></a>                    [&#39;#66f3&#39;, [102, 102, 255, 0.2]]];
<a name="line99"></a>
<a name="line100"></a>  for (var i = 0; i &lt; testColors.length; i++) {
<a name="line101"></a>    var r = goog.color.alpha.hexToRgba(testColors[i][0]);
<a name="line102"></a>    var t = testColors[i][1];
<a name="line103"></a>
<a name="line104"></a>    assertEquals(&#39;Red channel should match.&#39;, t[0], r[0]);
<a name="line105"></a>    assertEquals(&#39;Green channel should match.&#39;, t[1], r[1]);
<a name="line106"></a>    assertEquals(&#39;Blue channel should match.&#39;, t[2], r[2]);
<a name="line107"></a>    assertEquals(&#39;Alpha channel should match.&#39;, t[3], r[3]);
<a name="line108"></a>  }
<a name="line109"></a>
<a name="line110"></a>  var badColors = [&#39;&#39;, &#39;#g00&#39;, &#39;some words&#39;];
<a name="line111"></a>  for (var i = 0; i &lt; badColors.length; i++) {
<a name="line112"></a>    var e = assertThrows(
<a name="line113"></a>        goog.partial(goog.color.alpha.hexToRgba, badColors[i]));
<a name="line114"></a>    assertEquals(&quot;&#39;&quot; + badColors[i] + &quot;&#39; is not a valid alpha hex color&quot;,
<a name="line115"></a>        e.message);
<a name="line116"></a>  }
<a name="line117"></a>}
<a name="line118"></a>
<a name="line119"></a>function testHexToRgbaStyle() {
<a name="line120"></a>  assertEquals(&#39;rgba(255,0,0,1)&#39;,
<a name="line121"></a>               goog.color.alpha.hexToRgbaStyle(&#39;#ff0000ff&#39;));
<a name="line122"></a>  assertEquals(&#39;rgba(206,206,206,0.8)&#39;,
<a name="line123"></a>               goog.color.alpha.hexToRgbaStyle(&#39;#cecececc&#39;));
<a name="line124"></a>  assertEquals(&#39;rgba(51,204,170,0.2)&#39;,
<a name="line125"></a>               goog.color.alpha.hexToRgbaStyle(&#39;#3CA3&#39;));
<a name="line126"></a>  assertEquals(&#39;rgba(1,2,3,0.016)&#39;,
<a name="line127"></a>               goog.color.alpha.hexToRgbaStyle(&#39;#01020304&#39;));
<a name="line128"></a>  assertEquals(&#39;rgba(255,255,0,0.333)&#39;,
<a name="line129"></a>               goog.color.alpha.hexToRgbaStyle(&#39;#FFFF0055&#39;));
<a name="line130"></a>
<a name="line131"></a>  var badHexColors = [&#39;#12345&#39;, null, undefined, &#39;#.1234567890&#39;];
<a name="line132"></a>  for (var i = 0; i &lt; badHexColors.length; ++i) {
<a name="line133"></a>    var e = assertThrows(badHexColors[i] + &#39; is an invalid hex color&#39;,
<a name="line134"></a>        goog.partial(goog.color.alpha.hexToRgbaStyle, badHexColors[i]));
<a name="line135"></a>    assertEquals(&quot;&#39;&quot; + badHexColors[i] + &quot;&#39; is not a valid alpha hex color&quot;,
<a name="line136"></a>        e.message);
<a name="line137"></a>  }
<a name="line138"></a>}
<a name="line139"></a>
<a name="line140"></a>function testRgbaToHex() {
<a name="line141"></a>  assertEquals(&#39;#af13ffff&#39;, goog.color.alpha.rgbaToHex(175, 19, 255, 1));
<a name="line142"></a>  assertEquals(&#39;#357cf099&#39;, goog.color.alpha.rgbaToHex(53, 124, 240, 0.6));
<a name="line143"></a>  var badRgba = [[-1, -1, -1, -1], [0, 0, 0, 2], [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;],
<a name="line144"></a>                 [undefined, 5, 5, 5]];
<a name="line145"></a>  for (var i = 0; i &lt; badRgba.length; ++i) {
<a name="line146"></a>    var e = assertThrows(badRgba[i] + &#39; is not a valid rgba color&#39;,
<a name="line147"></a>        goog.partial(goog.color.alpha.rgbaArrayToHex, badRgba[i]));
<a name="line148"></a>    assertContains(&#39;is not a valid RGBA color&#39;, e.message);
<a name="line149"></a>  }
<a name="line150"></a>}
<a name="line151"></a>
<a name="line152"></a>function testRgbaToRgbaStyle() {
<a name="line153"></a>  var testColors = [[[175, 19, 255, 1], &#39;rgba(175,19,255,1)&#39;],
<a name="line154"></a>                    [[53, 124, 240, .6], &#39;rgba(53,124,240,0.6)&#39;],
<a name="line155"></a>                    [[10, 20, 30, .1234567], &#39;rgba(10,20,30,0.123)&#39;],
<a name="line156"></a>                    [[20, 30, 40, 1 / 3], &#39;rgba(20,30,40,0.333)&#39;]];
<a name="line157"></a>
<a name="line158"></a>  for (var i = 0; i &lt; testColors.length; ++i) {
<a name="line159"></a>    var r = goog.color.alpha.rgbaToRgbaStyle(testColors[i][0][0],
<a name="line160"></a>                                             testColors[i][0][1],
<a name="line161"></a>                                             testColors[i][0][2],
<a name="line162"></a>                                             testColors[i][0][3]);
<a name="line163"></a>    assertEquals(testColors[i][1], r);
<a name="line164"></a>  }
<a name="line165"></a>
<a name="line166"></a>  var badColors = [[0, 0, 0, 2]];
<a name="line167"></a>  for (var i = 0; i &lt; badColors.length; ++i) {
<a name="line168"></a>    var e = assertThrows(goog.partial(goog.color.alpha.rgbaToRgbaStyle,
<a name="line169"></a>        badColors[i][0], badColors[i][1], badColors[i][2], badColors[i][3]));
<a name="line170"></a>
<a name="line171"></a>    assertContains(&#39;is not a valid RGBA color&#39;, e.message);
<a name="line172"></a>  }
<a name="line173"></a>
<a name="line174"></a>  // Loop through all bad color values and ensure they fail in each channel.
<a name="line175"></a>  var badValues = [-1, 300, &#39;a&#39;, undefined, null, NaN];
<a name="line176"></a>  var color = [0, 0, 0, 0];
<a name="line177"></a>  for (var i = 0; i &lt; badValues.length; ++i) {
<a name="line178"></a>    for (var channel = 0; channel &lt; color.length; ++channel) {
<a name="line179"></a>      color[channel] = badValues[i];
<a name="line180"></a>      var e = assertThrows(color + &#39; is not a valid rgba color&#39;,
<a name="line181"></a>          goog.partial(goog.color.alpha.rgbaToRgbaStyle, color));
<a name="line182"></a>      assertContains(&#39;is not a valid RGBA color&#39;, e.message);
<a name="line183"></a>
<a name="line184"></a>      color[channel] = 0;
<a name="line185"></a>    }
<a name="line186"></a>  }
<a name="line187"></a>}
<a name="line188"></a>
<a name="line189"></a>function testRgbaArrayToRgbaStyle() {
<a name="line190"></a>  var testColors = [[[175, 19, 255, 1], &#39;rgba(175,19,255,1)&#39;],
<a name="line191"></a>                    [[53, 124, 240, .6], &#39;rgba(53,124,240,0.6)&#39;]];
<a name="line192"></a>
<a name="line193"></a>  for (var i = 0; i &lt; testColors.length; ++i) {
<a name="line194"></a>    var r = goog.color.alpha.rgbaArrayToRgbaStyle(testColors[i][0]);
<a name="line195"></a>    assertEquals(testColors[i][1], r);
<a name="line196"></a>  }
<a name="line197"></a>
<a name="line198"></a>  var badColors = [[0, 0, 0, 2]];
<a name="line199"></a>  for (var i = 0; i &lt; badColors.length; ++i) {
<a name="line200"></a>    var e = assertThrows(goog.partial(goog.color.alpha.rgbaArrayToRgbaStyle,
<a name="line201"></a>        badColors[i]));
<a name="line202"></a>
<a name="line203"></a>    assertContains(&#39;is not a valid RGBA color&#39;, e.message);
<a name="line204"></a>  }
<a name="line205"></a>
<a name="line206"></a>  // Loop through all bad color values and ensure they fail in each channel.
<a name="line207"></a>  var badValues = [-1, 300, &#39;a&#39;, undefined, null, NaN];
<a name="line208"></a>  var color = [0, 0, 0, 0];
<a name="line209"></a>  for (var i = 0; i &lt; badValues.length; ++i) {
<a name="line210"></a>    for (var channel = 0; channel &lt; color.length; ++channel) {
<a name="line211"></a>      color[channel] = badValues[i];
<a name="line212"></a>      var e = assertThrows(color + &#39; is not a valid rgba color&#39;,
<a name="line213"></a>          goog.partial(goog.color.alpha.rgbaToRgbaStyle, color));
<a name="line214"></a>      assertContains(&#39;is not a valid RGBA color&#39;, e.message);
<a name="line215"></a>
<a name="line216"></a>      color[channel] = 0;
<a name="line217"></a>    }
<a name="line218"></a>  }
<a name="line219"></a>}
<a name="line220"></a>
<a name="line221"></a>function testRgbaArrayToHsla() {
<a name="line222"></a>  var opaqueBlueRgb = [0, 0, 255, 1];
<a name="line223"></a>  var opaqueBlueHsl = goog.color.alpha.rgbaArrayToHsla(opaqueBlueRgb);
<a name="line224"></a>  assertArrayEquals(&#39;Conversion from RGBA to HSLA should be as expected&#39;,
<a name="line225"></a>                    [240, 1, 0.5, 1], opaqueBlueHsl);
<a name="line226"></a>
<a name="line227"></a>  var nearlyOpaqueYellowRgb = [255, 190, 0, 0.7];
<a name="line228"></a>  var nearlyOpaqueYellowHsl =
<a name="line229"></a>      goog.color.alpha.rgbaArrayToHsla(nearlyOpaqueYellowRgb);
<a name="line230"></a>  assertArrayEquals(&#39;Conversion from RGBA to HSLA should be as expected&#39;,
<a name="line231"></a>                    [45, 1, 0.5, 0.7], nearlyOpaqueYellowHsl);
<a name="line232"></a>
<a name="line233"></a>  var transparentPurpleRgb = [180, 0, 255, 0];
<a name="line234"></a>  var transparentPurpleHsl =
<a name="line235"></a>      goog.color.alpha.rgbaArrayToHsla(transparentPurpleRgb);
<a name="line236"></a>  assertArrayEquals(&#39;Conversion from RGBA to HSLA should be as expected&#39;,
<a name="line237"></a>                    [282, 1, 0.5, 0], transparentPurpleHsl);
<a name="line238"></a>}
<a name="line239"></a>
<a name="line240"></a>function testNormalizeAlphaHex() {
<a name="line241"></a>  var compactColor = &#39;#abcd&#39;;
<a name="line242"></a>  var normalizedCompactColor =
<a name="line243"></a>      goog.color.alpha.normalizeAlphaHex_(compactColor);
<a name="line244"></a>  assertEquals(&#39;The color should have been normalized to the right length&#39;,
<a name="line245"></a>               &#39;#aabbccdd&#39;, normalizedCompactColor);
<a name="line246"></a>
<a name="line247"></a>  var uppercaseColor = &#39;#ABCDEF01&#39;;
<a name="line248"></a>  var normalizedUppercaseColor =
<a name="line249"></a>      goog.color.alpha.normalizeAlphaHex_(uppercaseColor);
<a name="line250"></a>  assertEquals(&#39;The color should have been normalized to lowercase&#39;,
<a name="line251"></a>               &#39;#abcdef01&#39;, normalizedUppercaseColor);
<a name="line252"></a>}
<a name="line253"></a>
<a name="line254"></a>function testHsvaArrayToHex() {
<a name="line255"></a>  var opaqueSkyBlueHsv = [190, 1, 255, 1];
<a name="line256"></a>  var opaqueSkyBlueHex = goog.color.alpha.hsvaArrayToHex(opaqueSkyBlueHsv);
<a name="line257"></a>  assertEquals(&#39;The HSVA array should have been properly converted to hex&#39;,
<a name="line258"></a>               &#39;#00d4ffff&#39;, opaqueSkyBlueHex);
<a name="line259"></a>
<a name="line260"></a>  var halfTransparentPinkHsv = [300, 1, 255, 0.5];
<a name="line261"></a>  var halfTransparentPinkHex =
<a name="line262"></a>      goog.color.alpha.hsvaArrayToHex(halfTransparentPinkHsv);
<a name="line263"></a>  assertEquals(&#39;The HSVA array should have been properly converted to hex&#39;,
<a name="line264"></a>               &#39;#ff00ff7f&#39;, halfTransparentPinkHex);
<a name="line265"></a>
<a name="line266"></a>  var transparentDarkTurquoiseHsv = [175, 1, 127, 0.5];
<a name="line267"></a>  var transparentDarkTurquoiseHex =
<a name="line268"></a>      goog.color.alpha.hsvaArrayToHex(transparentDarkTurquoiseHsv);
<a name="line269"></a>  assertEquals(&#39;The HSVA array should have been properly converted to hex&#39;,
<a name="line270"></a>               &#39;#007f747f&#39;, transparentDarkTurquoiseHex);
<a name="line271"></a>}
<a name="line272"></a>
<a name="line273"></a>function testExtractHexColor() {
<a name="line274"></a>  var opaqueRed = &#39;#ff0000ff&#39;;
<a name="line275"></a>  var red = goog.color.alpha.extractHexColor(opaqueRed);
<a name="line276"></a>  assertEquals(&#39;The hex part of the color should have been extracted correctly&#39;,
<a name="line277"></a>               &#39;#ff0000&#39;, red);
<a name="line278"></a>
<a name="line279"></a>  var halfOpaqueDarkGreenCompact = &#39;#0507&#39;;
<a name="line280"></a>  var darkGreen =
<a name="line281"></a>      goog.color.alpha.extractHexColor(halfOpaqueDarkGreenCompact);
<a name="line282"></a>  assertEquals(&#39;The hex part of the color should have been extracted correctly&#39;,
<a name="line283"></a>               &#39;#005500&#39;, darkGreen);
<a name="line284"></a>
<a name="line285"></a>}
<a name="line286"></a>
<a name="line287"></a>function testExtractAlpha() {
<a name="line288"></a>  var colors = [&#39;#ff0000ff&#39;, &#39;#0507&#39;, &#39;#ff000005&#39;];
<a name="line289"></a>  var expectedOpacities = [&#39;ff&#39;, &#39;77&#39;, &#39;05&#39;];
<a name="line290"></a>
<a name="line291"></a>  for (var i = 0; i &lt; colors.length; i++) {
<a name="line292"></a>    var opacity = goog.color.alpha.extractAlpha(colors[i]);
<a name="line293"></a>    assertEquals(&#39;The alpha transparency should have been extracted correctly&#39;,
<a name="line294"></a>                 expectedOpacities[i], opacity);
<a name="line295"></a>  }
<a name="line296"></a>}
<a name="line297"></a>
<a name="line298"></a>function testHslaArrayToRgbaStyle() {
<a name="line299"></a>  assertEquals(&#39;rgba(102,255,102,0.5)&#39;,
<a name="line300"></a>               goog.color.alpha.hslaArrayToRgbaStyle([120, 100, 70, 0.5]));
<a name="line301"></a>  assertEquals(&#39;rgba(28,23,23,0.9)&#39;,
<a name="line302"></a>               goog.color.alpha.hslaArrayToRgbaStyle([0, 10, 10, 0.9]));
<a name="line303"></a>}
<a name="line304"></a>
<a name="line305"></a>function testRgbaStyleParsableResult() {
<a name="line306"></a>  var testColors = [[175, 19, 255, 1],
<a name="line307"></a>                    [53, 124, 240, .6],
<a name="line308"></a>                    [20, 30, 40, 0.3333333],
<a name="line309"></a>                    [255, 255, 255, 0.7071067811865476]];
<a name="line310"></a>
<a name="line311"></a>  for (var i = 0, testColor; testColor = testColors[i]; i++) {
<a name="line312"></a>    var rgbaStyle = goog.color.alpha.rgbaStyle_(testColor);
<a name="line313"></a>    var parsedColor = goog.color.alpha.hexToRgba(
<a name="line314"></a>        goog.color.alpha.parse(rgbaStyle).hex);
<a name="line315"></a>    assertEquals(testColor[0], parsedColor[0]);
<a name="line316"></a>    assertEquals(testColor[1], parsedColor[1]);
<a name="line317"></a>    assertEquals(testColor[2], parsedColor[2]);
<a name="line318"></a>    // Parsing keeps a 1/255 accuracy on the alpha channel.
<a name="line319"></a>    assertRoughlyEquals(testColor[3], parsedColor[3], 0.005);
<a name="line320"></a>  }
<a name="line321"></a>}
</pre>


</body>
</html>
